package org.jeecg.modules.system.util;

import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Slf4j
public class DateUtil {
    static SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static int minuteDiff(Date date1, Date date2){
        int minutes = 1;
        try {
            long from = date1.getTime();
            long to = date2.getTime();
            minutes = (int) ((to - from) / (1000 * 60));
        }catch (Exception e){
            log.error(e.getMessage());
        }
        return minutes;
    }

    public static int hoursDiff(Date date1, Date date2){
        int hours = 1;
        try {
            long from = date1.getTime();
            long to = date2.getTime();
            hours = (int) ((to - from) / (1000 * 60 * 60));
        }catch (Exception e){
            log.error(e.getMessage());
        }
        return hours;
    }
    public static int daysDiff(Date date1, Date date2){
        int days = 1;
        try {
            long from = date1.getTime();
            long to = date2.getTime();
            days = (int) ((to - from)/(1000 * 60 * 60 * 24));
        }catch (Exception e){
            log.error(e.getMessage());
        }
        return days;
    }

    public static Date addHours(Date date, int hours){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY, hours);
        return calendar.getTime();
    }
}
